﻿using QG.JobBack.BLL.Service;
using QG.JobBack.Core;
using QH.JobBack.Model;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace JobBack.Controllers
{
    public class ModuleController : Controller
    {
        private IModuleService _imoduleService;
        public ModuleController(IModuleService imoduleService)
        {
            _imoduleService = imoduleService;
        }

        /// <summary>
        /// 组主页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Index()
        {
            return View();
        }

        /// <summary>
        /// 分页查询
        /// </summary>
        /// <param name="page"></param>
        /// <param name="limit"></param>
        /// <returns></returns>
        public JsonResult GetModuleList(int page, int limit, string moduleName)
        {
            ResponseResult result = _imoduleService.GetModuleList(page, limit, moduleName);
            return Json(result, JsonRequestBehavior.AllowGet);
        }
        /// <summary>
        /// 组添加页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Add()
        {

            //获取父级组
            List<Module> moduleList = _imoduleService.GetModules().data;
            ViewBag.moduleList = moduleList;
            return View();
        }
        /// <summary>
        /// 添加一个组
        /// </summary>
        /// <param name="module"></param>
        /// <returns></returns>
        public JsonResult AddModule(Module module)
        {
            ResponseResult result = _imoduleService.AddModule(module);
            return Json(result);
        }
        /// <summary>
        /// 组修改页面
        /// </summary>
        /// <returns></returns>
        public ActionResult Update(int id)
        {
            //获取组对象
            ResponseResult result = _imoduleService.GetModule(id);
            //获取父级组
            List<Module> moduleList = _imoduleService.GetParentModule().data;
            ViewBag.moduleList = moduleList;
            return View(result.data);
        }
        /// <summary>
        /// 修改一个组
        /// </summary>
        /// <param name="module"></param>
        /// <returns></returns>
        public JsonResult UpdateModule(Module module)
        {
            ResponseResult result = _imoduleService.UpdateModule(module);
            return Json(result);
        }

        /// <summary>
        /// 根据ID删除一个组
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public JsonResult DeleteModuleById(int id)
        {
            ResponseResult result = _imoduleService.DeleteModuleById(id);
            return Json(result);
        }
        /// <summary>
        /// 查询所有父级组
        /// </summary>
        /// <returns></returns>
        public JsonResult GetParentModule()
        {
            ResponseResult result = _imoduleService.GetParentModule();
            return Json(result);
        }

        public JsonResult UpdateStatus(int id, bool status)
        {
            ResponseResult result = _imoduleService.UpdateStatus(id, status);
            return Json(result);

        }
    }
}